package com.play.ballen.me.ui

import android.content.Context
import android.content.Intent
import com.hjq.toast.ToastUtils
import com.play.ballen.R
import com.play.ballen.databinding.ActivityInvitePosterBinding
import com.play.ballen.me.vm.InvitePosterVM
import com.yuven.appframework.util.ClipboardUtils
import com.yuven.appframework.util.imageloader.ImageUtil
import com.yuven.appframework.util.setOnSingleClickListener
import com.yuven.baselib.component.BaseMVVMActivity
import com.yuven.baselib.utils.ResourceUtil
import com.yuven.baselib.utils.ViewUtils

class InvitePosterActivity : BaseMVVMActivity<InvitePosterVM, ActivityInvitePosterBinding>() {

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, InvitePosterActivity::class.java)
            context.startActivity(starter)
        }
    }

    override fun viewModelClass(): Class<InvitePosterVM> {
        return InvitePosterVM::class.java
    }

    override fun initView() {
        ViewUtils.translucentStatusBar(this, false)
        dataBinding.fakeStatusBar.layoutParams.height = ViewUtils.getStatusHeight()

        dataBinding.imgBack.setOnClickListener {
            finish()
        }
        dataBinding.tvLink.setOnSingleClickListener tag@{
            if (viewModel.invitePosterInfo.value == null) {
                return@tag
            }
            ClipboardUtils.setText(dataBinding.tvLink.text.toString().trim(), mContext)
            ToastUtils.show(ResourceUtil.getString(R.string.me_copy))
        }
        dataBinding.tvInviteCode.setOnSingleClickListener tag@{
            if (viewModel.invitePosterInfo.value == null) {
                return@tag
            }
            ClipboardUtils.setText(dataBinding.tvInviteCode.text.toString().trim(), mContext)
            ToastUtils.show(ResourceUtil.getString(R.string.me_copy))
        }
    }

    override fun initObserver() {
        super.initObserver()

        viewModel.invitePosterInfo.observe(this) {
            it.run {
                ImageUtil.instance.loadImage(0, 0, qrcode, dataBinding.imgQRCode)
                dataBinding.tvLink.text = url
                dataBinding.tvInviteCode.text = invite_code
            }
        }
    }

    override fun layoutId(): Int {
        return R.layout.activity_invite_poster
    }

    override fun initData() {
        viewModel.invitePoster()
    }

    override fun initIntent(intent: Intent?) {
    }

}